<template>
	<view class="order" >
		<uni-nav-bar left-icon="arrowleft" right-icon="search" title="退款/换货" @clickLeft="back" @clickRight="find" :fixed="true" class="top" status-bar></uni-nav-bar>
		<view class="uni-flex">
			<view class="flex-item" :class="{ active: active == 15 }" @click="cut(15)"><text>待处理</text></view>
			<view class="flex-item" :class="{ active: active == 6 }" @click="cut(6)"><text>已退款</text></view>
			<view class="flex-item" :class="{ active: active == 9 }" @click="cut(9)"><text>已换货</text></view>
			<view class="flex-item" :class="{ active: active ==10 }" @click="cut(10)"><text>已驳回</text></view>
		</view>
		<view class="list" v-if="dataList.length!=0">
			<view class="li" v-for="(item, index) in dataList" :key="index" @click="details(item.id)">
				<view class="shop">
					<image :src="item.image" class="imgthumb" :lazy-load = "true" mode="aspectFill"/>
					<view class="msg">
						<view class="order black">{{item.productName}}</view>
						<view class="sizr gray " v-for="(sku, index1) in item.sku" :key="index1">{{sku}}</view>
						<view class="order black">合计：￥{{item.orderPrice}}</view>
						
					</view>
				</view>
				<view class="genre">
					<text v-if="item.auditResult">{{item.auditResult.desp}}</text>
					<view class="msg">
						<view class="audit">查看详情</view>
					</view>
				</view>
				<view  class="orderfrom" >
						<text class="orderfrom">操作时间：{{item.operationTime}}</text>
				</view>
			</view>
		</view>
		<view class="pagination" v-if="dataList.length!=0">
			<view class="left" :class="{ forbid: paging.page == 1 }" @click="prev">
				<uni-icons type="arrowleft" size="20" color="#fff" class="icons" />
				上一页
			</view>
			<view class="center">{{ paging.page }}/{{ paging.total }}</view>
			<view class="right" :class="{ forbid: paging.page == paging.total }" @click="next">
				下一页
				<uni-icons type="arrowright" size="20" color="#fff" class="icons" />
			</view>
		</view>
		<view class="go-top" v-show="is_go_top" @click="backTop"><image src="/static/img/go_top.png" /></view>
		
		<view class="notavailable" v-if="dataList.length==0">
			<image src="../../static/img/notavailable.png" mode="widthFix"></image>
			<view class="nottext">暂时没有数据</view>
		</view>
	</view>
</template>

<script>
import { uniNavBar, uniIcons } from '@dcloudio/uni-ui';
import entrepot from '../../../servers/entrepot/entrepot.js';
export default {
	components: { uniNavBar, uniIcons },
	data() {
		return {
			active: 15,
			dataList: [],
			type:15,
			is_go_top:false,
			paging: {
				page: 1,
				total: 100
			}
		};
	},
	onPageScroll: function(e) {
		//nvue暂不支持滚动监听，可用bindingx代替
		if (e.scrollTop > 200) {
			this.is_go_top = true;
		} else {
			this.is_go_top = false;
		}
	},
	mounted() {
		this.getData()
	},
	methods: {
		getData(){
			uni.showLoading({
			    title: '数据加载中'
			});	
			var obj=new Object();
			obj.status=this.active;
			obj.currentPage= this.paging.page;
			obj.pageSize=10;
			entrepot.initData(obj)
				.then(res => {
				this.paging.total = Math.ceil(res.data.total / res.data.size);
				this.paging.page=res.data.current
				this.dataList=res.data.records.map(v => {
					v.image = this.imgCDNUrl + v.productImg;
					var sku=[];
					if(v.productSkuDesp){
						sku=v.productSkuDesp.split(",");
					}
					v.sku=sku;
					return v;
				});
				uni.hideLoading();
			
				})
				.catch(err => {
					console.log(new Error('请检查网络后重试'));
				});
			
		},
		back() {
			uni.navigateBack({
				delta: 1
			});
		},
		cut(e) {
			this.active = e;
			this.getData();
			this.paging.page=1;/* 切换后页面从1开始 */
		},
		find(){
			uni.navigateTo({
			    url: '/pages/entrepot/orderfind'
			});
		},
		next() {
			if (this.paging.page < this.paging.total) {
				this.paging.page += 1;
				this.getData();
			}
		},
		prev() {
			if (this.paging.page > 1) {
				this.paging.page -= 1;
				this.getData();
			}
		},
		// 计算距离顶部的高度，均分10等分，
		backTop() {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 200
			});
		},
	}
};
</script>

<style lang="less" scoped>
page {
	background: #ffffff;
}
.order {
	.uni-flex {
		position: fixed;
		z-index: 1;
		top: 44px;
		width: 100%;
		display: flex;
		flex-direction: row;
		box-shadow: 5rpx 0px 20rpx #c5c5c5;
		.flex-item {
			font-size: 28rpx;
			font-weight: 900;
			width: 33.33%;
			height: 89rpx;
			text-align: center;
			line-height: 89rpx;
			background: #ffffff;
		}
		.flex-item.active {
			text {
				color: #bd3c8c;
				border-bottom: 3rpx solid #bd3c8c;
			}
		}
	}
	.list {
		border-top: 26rpx solid #f6f6f6;
		padding: 89rpx 20rpx;
		.li {
			position: relative;
			padding: 50rpx 20rpx;
			margin: 15rpx 0;
			background: #fff;
			border-bottom: 1px solid #e1e1e1;
			border-radius: 10rpx;
			.shop {
				position: relative;
				display: flex;
				flex-direction: row;
				image {
					width: 230rpx;
					height: 230rpx;
					border-radius: 10rpx;
				}
				.msg {
					width: 431rpx;
					margin-left: 37rpx;
					line-height: 46rpx;
					.order {
						font-size: 28rpx;
					}
					.gray {
						color: #999999;
						font-size: 26rpx;
						line-height: 42rpx;
					}
				}
			}
			.genre {
				color: #bd3c8c;
				display: flex;
				flex-direction: row;
				padding-top: 57rpx;
				.orderfrom {
					width: 450rpx;
					font-size: 26rpx;
				}
				.msg {
					color: #999999;
					font-size: 26rpx;
					.audit {
						position: absolute;
						right: 20rpx;
						bottom: 35rpx;
						width: 180rpx;
						height: 64rpx;
						border-radius: 64rpx;
						line-height: 64rpx;
						border: 1px solid #f70225;
						color: #f70225;
						text-align: center;
					}
				}
			}
		}
		.li:nth-last-child(1) {
			border-bottom: none;
		}
	}
}
</style>
